package com.itheima.pinda.impl.truck;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.DTO.entity.pojo.truck.PdTruckTypeGoodsType;
import com.itheima.pinda.feign.service.truck.PdTruckTypeGoodsTypeService;
import com.itheima.pinda.mapper.truck.PdTruckTypeGoodsTypeMapper;
import com.itheima.pinda.utils.CustomIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 车辆类型与货物类型关联表 服务实现类
 * </p>
 *
 * @author xy
 * @since 2021-11-09
 */
@Service
@Transactional
public class PdTruckTypeGoodsTypeServiceImpl extends ServiceImpl<PdTruckTypeGoodsTypeMapper, PdTruckTypeGoodsType> implements PdTruckTypeGoodsTypeService {

    @Autowired
    private CustomIdGenerator idGenerator;

    @Override
    public void batchSave(List<PdTruckTypeGoodsType> truckTypeGoodsTypes) {
        for (PdTruckTypeGoodsType truckTypeGoodsType :
                truckTypeGoodsTypes) {
            truckTypeGoodsType.setId(idGenerator.nextId(truckTypeGoodsType)+"");
        }
        saveBatch(truckTypeGoodsTypes);
    }

    @Override
    public List<PdTruckTypeGoodsType> seletGid(String tid) {
        if (ObjectUtils.isEmpty(tid)){
            throw new NullPointerException("你传的值为空");
        }
        QueryWrapper<PdTruckTypeGoodsType> wrapper = new QueryWrapper<>();
        wrapper.eq("truck_type_id",tid);
        List<PdTruckTypeGoodsType> list = super.baseMapper.selectList(wrapper);

        return list;
    }
}
